﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using PHMEE.Constants;
using Volo.Abp.AspNetCore.SignalR;

namespace PHMEE.Admin
{
    [Authorize]
    public class ChatHub : AbpHub
    {
        /// <summary>
        /// 默认route： /signalr-hubs
        /// </summary>
        public ChatHub()
        {
            
        }

        /// <summary>
        /// 当前客户端发送消息
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendMessage(string message)
        {
            await Clients.Caller.SendAsync(PhmeeConst.SignalRReceiveMessage, message);
        }

        /// <summary>
        /// 指定用户id发送消息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendMessageDirectUser(string userId, string message)
        {
            await Clients.User(userId).SendAsync(PhmeeConst.SignalRReceiveMessage, message);
        }

        /// <summary>
        /// 所有客户端发送消息
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendMessageToAll(string message)
        {
            await Clients.All.SendAsync(PhmeeConst.SignalRReceiveMessage, message);
        }

        /// <summary>
        /// 当前客户端发送消息（带上用户信息）
        /// </summary>
        /// <param name="user"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendMessageWithUser(string user, string message)
        {
            await Clients.Caller.SendAsync(PhmeeConst.SignalRReceiveMessage, user, message);

        }

        /// <summary>
        /// 所有客户端发送消息(带上用户信息)
        /// </summary>
        /// <param name="user"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendMessageWithUserToAll(string user, string message)
        {
            await Clients.All.SendAsync(PhmeeConst.SignalRReceiveMessage, user, message);
        }


    }
}
